package com.lingnan.controller;


import com.lingnan.entity.po.Blacklist;
import com.lingnan.entity.vo.Result;
import com.lingnan.service.BlacklistService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/blacklist")
public class BlacklistController {

    @Autowired
    private BlacklistService blacklistService;

    @PostMapping
    public Result addBlacklist(@Validated @RequestBody Blacklist blacklist) {
        return blacklistService.addBlacklist(blacklist);
    }

    @PutMapping("/revoke/{id}")
    public Blacklist revokeBlacklist(
            @PathVariable Long id,
            @RequestHeader("X-Operator-Id") Long operatorId) {
        return blacklistService.revokeBlacklist(id, operatorId);
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable Long id) {
        return blacklistService.getById(id);
    }

    @GetMapping
    public Result getPage(
            @RequestParam(value = "page", defaultValue = "1") int page,
            @RequestParam(value = "size", defaultValue = "10") int size,
            @RequestParam(value = "sourceId", required = false) Long sourceId,
            @RequestParam(value = "targetId", required = false) Long targetId,
            @RequestParam(value = "targetType", required = false) Integer targetType,
            @RequestParam(value = "status", required = false) Integer status) {
        return blacklistService.getBlacklistPage(
                page, size, sourceId, targetId, targetType, status);
    }
}